<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of login
 *
 * @author Gmax
 */
class Controller_Login extends System_App_Controller_Abstract {
    public function index(){
        $this->view->message = ( isset($_SESSION['err_msg']) )?$_SESSION['err_msg']:'';
    }
    
    public function login(){
        $this->desableView();
        
        if( isset( $_POST['login'] )){
            $user = new Model_User();
            if( $user->login( $_POST['login'],$_POST['password']) ){	
                $_SESSION['user_log'] = true;
                $_SESSION['user_id'] = $user->getId();
                
                $urlRedirect = ( isset( $_SESSION['login_redirect'] ) )?$_SESSION['login_redirect']:'/';
                
                header( 'location: '.$urlRedirect );
                unset( $_SESSION['login_redirect']);
                unset( $_SESSION['err_msg']);
                exit;
            }else{
                $_SESSION['err_msg'] = 'erreur d\'identification';
                header( 'location: /login/' );
                exit;
            }
        }
    }
    public function logout(){
        $this->desableView();
        $_SESSION['user_log'] = false;
        unset($_SESSION['user_id']);
        header( 'location: /' );
        exit;
    }
}

?>
